<template>
	<view class="rectify-container">
		<rectify-item v-if="recordList.length !== 0" :rectifyList="recordList"></rectify-item>
		<view v-else>
			<van-empty description="暂无记录" />
		</view>
		<uni-load-more v-if="recordList && recordList.length >= 5" :status="status" />
	</view>
</template>

<script>
	import RectifyItem from '../components/rectifyItem.vue'
	import dayjs from 'dayjs'
	export default {
		components: {
			RectifyItem
		},
		data() {
			return {
				status: 'more',
				active: 0,
				params: {
					所属网格id: null,
					网格员id: null,
					整改状态: 0,
					pagination: {
						current: 1,
						pageSize: 5
					},
					sorter: {
						field: "id",
						order: 1
					}
				},
				recordList: null
			}
		},
		onLoad() {
			this.params.所属网格id = uni.getStorageSync('gridInfo').所属网格id
			this.params.网格员id = uni.getStorageSync('gridInfo').id
			this.getRectifyRecord()
		},
		onReachBottom() {
			console.log('触发上拉')
			if(this.status !== 'noMore' && this.recordList) {
				this.status = 'loading'
				this.getMoreRectify()
			}
		},
		methods: {
			getRectifyRecord() {
				this.$http.post('gridSystem/check/solveList', this.params).then(res => {
					if (res.code === 10000) {
						console.log(res)
						if (res.data.list !== null) {
							res.data.list.forEach(item => {
								item.整改开始日期 = dayjs(item.整改开始日期).format('YYYY-MM-DD')
							})
						}
						this.recordList = res.data.list
					}
				})
			},
			getMoreRectify() {
				this.params.pagination.current++
				this.$http.post('gridSystem/check/solveList', this.params).then(res => {
					if(res.code === 10000){
						if (res.data.list !== null) {
							res.data.list.forEach(item => {
								item.整改开始日期 = dayjs(item.整改开始日期).format('YYYY-MM-DD')
							})
						}
						this.recordList = this.recordList && this.recordList.concat(res.data.list)
						if(this.recordList.length === res.data.total){
							this.status = 'noMore'
						}
					}
				})
			}
		}
	}
</script>

<style lang="scss">
	.van-empty {
		background-color: #fff;
	}
	.rectify-container {
		background-color: #f5f5f5;
		// padding-bottom: 20rpx;
	}
</style>
